import 'package:flutter/cupertino.dart';

import '../pages/bars.dart';
import '../pages/shop.dart';
import '../pages/dialog.dart';

// 1.配置路由
final Map routes = {
  "/": (context) => const Bars(),
  "/dialog": (context) => const DialogPage(),
  "/shop": (context, {arguments}) => ShopPage(arguments: arguments)
};

// 2.配置onGenerateRoute 固定写法 这个方法相当于中间件 这里面可以做权限判断
var onGenerateRoute = (RouteSettings settings) {
  // print(settings);
  // print(settings.name);
  // print(settings.arguments);
  // 统一处理
  final String? name = settings.name; // /news 或者 /search
  final Function? pageContentBuilder =
      routes[name]; // Function (context) => const NewsPage()
  if (pageContentBuilder != null) {
    if (settings.arguments != null) {
      final Route route = CupertinoPageRoute(
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));
      return route;
    } else {
      final Route route =
          CupertinoPageRoute(builder: (context) => pageContentBuilder(context));
      return route;
    }
  }
  return null;
};
